<?php

/*
  Action	$4

  +2$
  Reveal cards from your deck until you reach the end of the deck.
  At any point you may choose to stop. return the last revealed card to the top of your deck and resume your turn.
  Discard all revealed cards.

 */

class Portal extends Card implements iAction, iKingdom, iAddiction {

    public function __construct() {
        parent::__construct("Portal", 4);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+2$",
            "Reveal cards from your deck until you reach the end of the deck.  At any point you may choose to stop. return the last revealed card to the top of your deck and resume your turn.  Discard all revealed cards.");
    }

    public function play(Game $game, $isRealCard) {

        $game->addMoney(new Price(2));

        $card = $game->removeCardFromDrawDeck();
        ScreenDisplay::addScreenMessage($game, true, " draw " . nicePrint($card), " draws ".ScreenDisplay::$LMSG);
        $discarded_cards = array();
        while ($card) {
            
            $options = array(new Option(1, "Discard it"), new Option(2, "Put it back on top"));

            $output = MySocket::GetUserReply($game, Input_ChooseOne, $options, 1, 1, null, "You drawed ".  $card->getValue().", Please choose");
            $answer = $output[0];
            
            if ($answer == 'Discard it') {
                $discarded_cards[] = $card;
                $card = $game->removeCardFromDrawDeck();
                if ($card) {
                    ScreenDisplay::addScreenMessage($game, false," and discard it", "and discards it");
                    ScreenDisplay::addScreenMessage($game, true,"draw ".  nicePrint($card),"draws ". ScreenDisplay::$LMSG);
                }
                else {
                    $game->discardTempDiscardCards($discarded_cards);
                    ScreenDisplay::addScreenMessage($game, false," and discard it", "and discards it");
                    ScreenDisplay::addScreenMessage($game, true, " draw nothing" , "draws nothing");
                    break;
                }
            } else {
                ScreenDisplay::addScreenMessage($game, false," and put it on top of your deck ","and put it on top of his deck");
               $game->putCardOnTopOfDrawDeck($card);
               $game->discardTempDiscardCards($discarded_cards);
               break;
            }
        }

        $game->cardActionFinished();
        return true;
    }

}

?>